﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;
using Yule8xCommon.Db;

namespace Yule8xWechat.PublicServices
{
    public partial class AreaService : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string pid = RequestUtil.GetString("pid", maxLen:16).Trim();
            string cid = RequestUtil.GetString("cid", maxLen: 16).Trim();
            string action = RequestUtil.GetString("action", maxLen: 16);
            string sqlstmt = string.Empty;
            switch (action)
            {
                case "getcity":
                    sqlstmt = "pid="+pid+" and level=2";
                    break;
                case "getarea":
                    sqlstmt = "pid=" + pid + " and cid="+cid+" and level=3";
                    break;
                default:
                    sqlstmt = "level=1";
                    break;
            }
            DataTable dt=DbFactory.Init(AppInfo.conn_yule8x_agent).ExecuteDataTable("select code, name, pid, cid, aid, level from t_area where " + sqlstmt);
            string content = JSON.ConvertToJson(dt);
            Response.Write(content);
            //ResponseUtil.AjaxWrite(JSON.ConvertToJson(dt));

        }
    }
}